<?php
session_start();
require_once './config/config.php';
require_once './lib/http/HTTP.php';
require_once './lib/smarty/libs/Smarty.class.php';
require_once './app/controller/controller_quelle.php';
require_once './app/controller/controller_auth.php';
require_once './app/controller/controller_bewerten.php';
require_once './app/model/model_dbhandler.php';




$smarty = new Smarty;
$contr_quelle = new Quelle ($smarty);
$contr_bewerten = new Bewerten(_quelle_);
$smarty -> template_dir = './app/view/quelle';
$smarty -> compile_dir = './lib/smarty/templates_c/quelle';
$smarty -> config_dir = './lib/smarty/configs/';
$smarty -> cache_dir = './lib/smarty/cache/';

if (isset($_REQUEST["ladeQuelleArt"])) {
	$contr_quelle -> loadArtOverview(_quelle_);
	die;
}

if (isset($_REQUEST["ladeQuelleKategorie"])) {
	$contr_quelle -> ladeKategorieOverview(_quelle_);
	die;
}

if (isset($_REQUEST["ladeQuelleKriterien"])) {
	$contr_quelle -> ladeKriterienOverview($_REQUEST["id"],_quelle_);
	die;
}

if (isset($_REQUEST["speicherNeueKategorie"])) {
	$contr_quelle -> speicherKategorie($_REQUEST["value"], $_REQUEST["art_id"]);
	die;
}

if (isset($_REQUEST["changeWeightKriterium"])) {
	$contr_quelle -> changeKriteriumWeight($_REQUEST["id"], $_REQUEST["value"]);
	die;
}

if (isset($_REQUEST["deleteKriterium"])) {
	$contr_quelle -> deleteKriterium($_REQUEST["id"], $_REQUEST["art_id"]);
	die;
}

if (isset($_REQUEST["speicherNeueKriterien"])) {
	$contr_quelle -> speicherKriterium($_REQUEST["value"], $_REQUEST["art_id"],_quelle_);
	die;
}

if (isset($_REQUEST["speicherNeueQuelle"])) {
	$key = "";
	$key = $contr_quelle -> speicherArt($_REQUEST["furz"], _quelle_);
	if ($_REQUEST["quelle"] == 1) {
		if (trim($_REQUEST["url"]) != "") {
			$contr_quelle -> speicherWWWQuelle($_REQUEST["url"], $key,1);
		}
	}
	else {
		if ($_FILES["datei"]["error"] != 4) {
			$contr_quelle -> speicherPRINTQuelle($_FILES, $key,2);
		}
	}
	//
	HTTP::redirect('quelle.php');
}

if (isset($_REQUEST["deleteArt"])) {
	$contr_quelle -> deleteQuelle ($_REQUEST["id"]);
	die;
}

if (isset($_REQUEST["deleteKategorie"])) {
	$contr_quelle -> deleteKategorie ($_REQUEST["id"], $_REQUEST["art_id"]);
	die;
}

if (isset($_REQUEST["addComment"])) {
	$smarty -> assign ('content', $contr_quelle -> ladeComment($_REQUEST["id"]));
	$smarty -> display ('addComment.tpl');
	die;
}

if (isset($_REQUEST["saveComment"])) {
	$contr_quelle -> saveComment($_REQUEST["id"], $_REQUEST["comment"]);
	die;
}


if (isset($_REQUEST["changeWeightKategorie"])) {
	$contr_quelle -> changeKategorieWeight($_REQUEST["id"], $_REQUEST["value"]);
	die;
}
/////

if (isset($_REQUEST["bewerten"])) {
	$smarty -> assign ('data',$contr_bewerten -> ladeBewertung($_REQUEST["id"]));
	$smarty -> assign ("art_id", $_REQUEST["id"]);
	$smarty -> assign ('js', '<script type="text/javascript" src="public/javascript/quelle/quelle_bewerten.js"></script><script type="text/javascript" src="public/javascript/changeVote.js"></script>');
	$smarty -> assign ('css', '<link rel="stylesheet" type="text/css" href="public/css/ext.css" />');
	$smarty -> display('../master/head.tpl');
	$smarty -> display('quelle_bewerten.tpl');
	$smarty -> display('../master/foot.tpl');
	die;
}

if (isset($_REQUEST["speicherPunkte"])) {
	$contr_bewerten -> speicherPunkte($_REQUEST["id"], $_REQUEST["value"]);
	die;
}
if (isset($_REQUEST["addCommentPunkte"])) {
	$smarty -> assign ('content' , $contr_bewerten -> ladeKommentarPunkte($_REQUEST["id"]));
	$smarty -> display('addCommentPunkte.tpl');
	die;
}

if (isset($_REQUEST["saveCommentPunkte"])) {
	$contr_bewerten -> speicherKommentarPunkte($_REQUEST["id"], $_REQUEST["comment"]);
	die;
}

//////
if (isset($_REQUEST["viewKriterien"])) {
	$smarty -> assign ("art_id", $_REQUEST["id"]);
	$smarty -> assign ('js', '<script type="text/javascript" src="public/javascript/quelle/quelle_kriterien.js"></script><script type="text/javascript" src="public/javascript/quelle/change_quelle_kategorie_weight.js"></script>');
	$smarty -> assign ('css', '<link rel="stylesheet" type="text/css" href="public/css/ext.css" />');
	$smarty -> display('../master/head.tpl');
	$smarty -> display('quelle_kriterien.tpl');
	$smarty -> display('../master/foot.tpl');
	die;
}

if (isset($_REQUEST["viewKategorie"])) {
	$smarty -> assign ("art_id", $_REQUEST["id"]);
	$smarty -> assign ('js', '<script type="text/javascript" src="public/javascript/quelle/quelle_kategorie.js"></script><script type="text/javascript" src="public/javascript/quelle/change_quelle_kategorie_weight.js"></script>');
	$smarty -> assign ('css', '<link rel="stylesheet" type="text/css" href="public/css/ext.css" />');
	$smarty -> display('../master/head.tpl');
	$smarty -> display('quelle_kategorie.tpl');
	$smarty -> display('../master/foot.tpl');
	die;
}

$smarty -> assign ('js', '<script type="text/javascript" src="public/javascript/quelle/quelle_art.js"></script><script type="text/javascript" src="public/javascript/swap.js"></script>');
$smarty -> assign ('css', '<link rel="stylesheet" type="text/css" href="public/css/ext.css" />');
$smarty -> display('../master/head.tpl');
$smarty -> display('quelle_uebersicht.tpl');
$smarty -> display('../master/foot.tpl');
?>